package com.woniuxy.service.impl;

import com.woniuxy.dao.MenuDao;
import com.woniuxy.entity.Menu;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName RbacMenuServiceImpl
 * @Description TODO
 * @Author LI.hh
 * @Date 2022/9/10 15:25
 * @Version 1.0
 */
@Service
public class RbacMenuServiceImpl implements RbacMenuService {
    @Autowired
    MenuDao menuDao;
    @Override
    public ResponseEntity findAll(int id) {
        List<Menu> list =menuDao.showMenuByUserId(id);
        return new ResponseEntity(200,"成功",list);
    }

    @Override
    public ResponseEntity editOne(Menu rbacMenu) {
        int i = menuDao.editOne(rbacMenu);
        if (i>0){
            return new ResponseEntity(200,"成功修改");
        }else {
            return new ResponseEntity(500,"修改失败");
        }
    }

    @Override
    public ResponseEntity updateMenu(int id, Integer fid) {
        if(fid == 0){
            fid = null;
        }
        int i = menuDao.updateMenu(id,fid);
        if (i>0){
            return new ResponseEntity(200,"成功修改");
        }else {
            return new ResponseEntity(500,"修改失败");
        }
    }

    @Override
    public ResponseEntity findAllMenu() {
        List<Menu> list =menuDao.findAllMenu();
        return new ResponseEntity(200,"成功",list);
    }

    @Override
    public ResponseEntity findAllId(int id) {
        List<Integer> list =menuDao.findAllId(id);
        return new ResponseEntity(200,"成功",list);
    }

    @Override
    public ResponseEntity deleteMenu(int id) {
        menuDao.deleteMenu(id);
        return new ResponseEntity(200,"成功删除",null);
    }

    @Override
    public ResponseEntity insertMenu(int id,int roleId) {
        menuDao.insertMenu(roleId,id);
        return new ResponseEntity(200,"成功添加",null);
    }

    @Override
    public ResponseEntity addOne(Menu rbacMenu) {
        menuDao.addOne(rbacMenu);
        return new ResponseEntity(200,"成功添加",null);
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        menuDao.deleteOne(id);
        return new ResponseEntity(200,"成功删除",null);
    }


}
